﻿using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;

using LongNet.Threading;

namespace LongNet.Util
{
    /// <summary>
    /// Provides a set of static methods for extensions.
    /// </summary>
    public static class ObjectExtensions
    {
        #region Static Methods

        /// <summary>
        /// Indicates whether the specified <see cref="T:Object"/> is null.
        /// </summary>
        /// <param name="value">A <see cref="T:Object"/> reference.</param>
        /// <returns>true if the value parameter is null; otherwise, false.</returns>
        public static bool IsNull(this object value)
        {
            return (value == null);
        }

        /// <summary>
        /// Determines whether the specified <see cref="T:Object"/> instances are the same instance.
        /// </summary>
        /// <param name="value">The first <see cref="T:Object"/> to compare.</param>
        /// <param name="other">The second <see cref="T:Object"/> to compare.</param>
        /// <returns>true if objA is the same instance as objB or if both are null references; otherwise, false.</returns>
        public static bool IsReferenceEquals(this object value, object other)
        {
            return object.ReferenceEquals(value, other);
        }

        /// <summary>
        /// Converts a .NET object to a string of Json.
        /// </summary>
        /// <param name="value">Object to convert.</param>
        /// <returns>A json string represting the object parameter. The return value will be null of the object is null.</returns>
        public static string ToJsonString(this object value)
        {
            return Serializer.ConvertToJsonString(value);
        }

        /// <summary>
        /// Converts a .NET object to a string of Json.
        /// </summary>
        /// <param name="value">Object to convert.</param>
        /// <param name="knownTypes">
        /// An <see cref="T:IEnumerable`1"/> of <see cref="T:System.Type"/> that contains 
        /// the types that may be present in the object graph.
        /// </param>
        /// <returns>A json string represting the object parameter. The return value will be null of the object is null.</returns>
        public static string ToJsonString(this object value, IEnumerable<Type> knownTypes)
        {
            return Serializer.ConvertToJsonString(value, knownTypes);
        }

        #endregion
    }
}
